using MicroMsg.Common.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
namespace MicroMsg.Storage
{
	public class SnsRegion
	{
		public List<ulong> list_0 = new List<ulong>();
		public List<uint> times = new List<uint>();
		public SnsRegion()
		{
		}
		public SnsRegion(List<ulong> param_ids, uint requestTime)
		{
			this.list_0.AddRange(param_ids);
			this.times.Add((uint)param_ids.get_Count());
			this.times.Add(requestTime);
		}
		private static int coverCount(int start1, int len1, int start2, int len2)
		{
			if (start1 + len1 <= start2)
			{
				return 0;
			}
			if (start2 + len2 <= start1)
			{
				return 0;
			}
			int num = Math.Max(start1, start2);
			int num2 = Math.Min(start1 + len1, start2 + len2);
			return num2 - num;
		}
		private void times_remove(int index, int int_0)
		{
			bool flag = false;
			if (int_0 <= 0)
			{
				return;
			}
			int i = 0;
			int num = 0;
			while (i < this.times.get_Count())
			{
				int num2 = SnsRegion.coverCount(num, (int)this.times.get_Item(i), index, int_0);
				if (num2 == 0)
				{
					num += (int)this.times.get_Item(i);
				}
				else
				{
					List<uint> list;
					int num3;
					(list = this.times).set_Item(num3 = i, list.get_Item(num3) - (uint)num2);
					index += num2;
					int_0 -= num2;
					if (this.times.get_Item(i) == 0u)
					{
						flag = true;
					}
					if (int_0 <= 0)
					{
						break;
					}
				}
				i += 2;
			}
			if (flag)
			{
				while (this.times.get_Count() > 0 && this.times.get_Item(0) == 0u)
				{
					this.times.RemoveRange(0, 2);
				}
			}
		}
		public void removeTop(int int_0)
		{
			if (int_0 <= this.list_0.get_Count() && int_0 > 0)
			{
				this.list_0.RemoveRange(0, int_0);
				this.times_remove(0, int_0);
				return;
			}
			Log.smethod_1("SnsPage", string.Concat(new object[]
			{
				"SnsObjIDRegion removeTop error! count= ",
				this.list_0.get_Count(),
				",num=",
				int_0
			}));
		}
		public void remove(ulong ulong_0)
		{
			int num = this.list_0.IndexOf(ulong_0);
			if (num < 0)
			{
				return;
			}
			this.list_0.Remove(ulong_0);
			this.times_remove(num, 1);
		}
		public uint getTimeMin(int index, int count)
		{
			int num = 0;
			uint num2 = 0u;
			for (int i = 0; i < this.times.get_Count(); i += 2)
			{
				if (0 < SnsRegion.coverCount(num, (int)this.times.get_Item(i), index, count))
				{
					num2 = Math.Min(num2, this.times.get_Item(i + 1));
				}
				num += (int)this.times.get_Item(i);
			}
			return num2;
		}
		public void breakTailAt(ulong id_tail)
		{
			if (Enumerable.Last<ulong>(this.list_0) > id_tail)
			{
				return;
			}
			for (int i = 0; i < this.list_0.get_Count(); i++)
			{
				if (this.list_0.get_Item(i) <= id_tail)
				{
					this.list_0.RemoveRange(i, this.list_0.get_Count() - i);
					this.times_remove(i, this.list_0.get_Count() - i);
				}
			}
		}
		public bool isEmpty()
		{
			return this.list_0.get_Count() <= 0;
		}
		public void dump()
		{
			string text = "id=";
			using (List<ulong>.Enumerator enumerator = this.list_0.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					ulong current = enumerator.get_Current();
					text = text + current + ",";
				}
			}
			text += "time=";
			for (int i = 0; i < this.times.get_Count(); i += 2)
			{
				object obj = text;
				text = string.Concat(new object[]
				{
					obj,
					"(",
					this.times.get_Item(i),
					"|",
					this.times.get_Item(i + 1),
					"),"
				});
			}
		}
	}
}
